package com.atguigu.yygh.cmn.demo;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.write.builder.ExcelWriterBuilder;
import com.alibaba.excel.write.metadata.WriteSheet;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author luoyin
 * @Date 19:07 2022/9/23
 **/
public class WriterExcel {
    /*public static void main(String[] args) {
        String fileName = "C:\\Users\\luoyin\\Desktop\\学生.xlsx";
        List<User> data = new ArrayList<>();
        data.add(new User(1L,"张三",34));
        data.add(new User(2L,"李四",25));
        data.add(new User(3L,"王五",32));
        data.add(new User(4L,"赵六",31));
        EasyExcel.write(fileName,User.class).sheet("学生表").doWrite(data);
    }*/
    public static void main(String[] args) {
        String fileName = "C:\\Users\\luoyin\\Desktop\\学生.xlsx";
        List<User> data = new ArrayList<>();
        data.add(new User(1L,"张三",34));
        data.add(new User(2L,"李四",25));
        data.add(new User(3L,"王五",32));
        data.add(new User(4L,"赵六",31));
        ArrayList<Student> students = new ArrayList<>();
        students.add(new Student(1L,"小王"));
        students.add(new Student(2L,"小罗"));
        students.add(new Student(3L,"小李"));
        ExcelWriter writer = EasyExcel.write(fileName).build();
        WriteSheet sheet1 = EasyExcel.writerSheet(0, "学生表").head(Student.class).build();
        WriteSheet sheet2= EasyExcel.writerSheet(1, "用户表").head(User.class).build();
        writer.write(students,sheet1);
        writer.write(data,sheet2);
        writer.finish();
    }
}
